<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
	<style type="text/css">
		*{
			margin: 0;
			padding: 0;
		}
		.banner{
			width: 1200px;
			height: 400px;
			background-color: pink;
			margin: 0 auto;
			position: relative;
		}
		.banner img{
			width: 100%;
			display: none;
		}

		.banner .active{
			display: block;
		}
		.icon{
			position: absolute;
			bottom: 5px;
			left: 50%;
			transform: translate(-50%);
		}
		.icon span{
			display: inline-block;
			width: 20px;
			height: 20px;
			background-color:rgba(0, 0, 0, 0.5) ;
			color: #fff;
			text-align: center;
			line-height: 20px;
			font-size: 12px;
		}
		.icon .select{
			background: white;
			color: #000;
		}
		.left,.right{
			position: absolute;
			top: 50%;
			transform: translateY(-50%);
			width: 40px;
			height: 80px;
			line-height: 80px;
			text-align: center;
			background-color: rgba(0, 0, 0, 0.5);
			color: #fff;
		}
		.left{
			left: 0;
		}
		.right{
			right: 0;
		}
		.left:hover{
			cursor: pointer;
		}
		.right:hover{
			cursor: pointer;
		}
	</style>

</head>
<body>

	<div class="banner">
		<div>
			<img src="./img/a1.webp" class="active">
			<img src="./img/a2.webp">
			<img src="./img/a3.webp">
			<img src="./img/a4.webp">
		</div>
		<div class="icon">
			<span class="select">1</span>
			<span>2</span>
			<span>3</span>
			<span>4</span>
		</div>
		<div class="left">
			<
		</div>
		<div class="right">	
			>
		</div>
	</div>
<script type="text/javascript">

	let time = null
	function handle() {
		right.onclick
	}
	time = setInterval(handle,3000)

	//定时器和用户交互 起冲突 定时器停止
	let banner = document.querySelector('.banner')
	banner.onmouseenter = function() {
		clearInterval(time)
	}

	//鼠标移开 打开定时器
	banner.onmouseleave = function() {
	time = setInterval(handle,3000)
		
	}


	var imgs = document.querySelectorAll('.banner img')
	var spans = document.querySelectorAll('.icon span')
	for(let i = 0; i <spans.length;i++){
		spans[i].onclick = function(){
			document.querySelector('.active').className = ''
			document.querySelector('.select').className = ''
			this.className = 'select'
			imgs[i].className = 'active'
		}
	}
	//获取右点击事件
	let right = document.querySelector('.right')
	right.onclick = function() {
		let select = document.querySelector('.select')
		if(select.nextElementSibling == null){
			spans[0].onclick() //调用上面的spans[i].onclick = function(){} 
		}else{
			//当点击右侧按钮时，相当于点击的span下一个兄弟元素
			select.nextElementSibling.onclick()
		}
	
	}
	//获取左点击事件
	let left = document.querySelector('.left')
		left.onclick = function() {
		let select = document.querySelector('.select')
		if(select.previousElementSibling == null){
			spans[3].onclick()
		}else{
			//当点击左侧按钮时，相当于点击的span上一个兄弟元素
			select.previousElementSibling.onclick()
		}
	}
	
/*	let time = null
	time = setInterval(function() {
		right.onclick()
	},1000)
	let banner = document.querySelector('.banner')
	banner.addEventListener('mouseover',function() {
		clearInterval(time)
	})
	banner.addEventListener('mouseleave',function() {
		clearInterval(time)
		time = setInterval(function() {
		right.onclick()
	},1000)
	})*/
</script>
</body>
</html>